#ifndef __IL_BUTTON__H__
#define __IL_BUTTON__H__

#include "ILControl.h"
#include "ILLabel.h"
#include "ILImage.h"

#define IL_BUTTON_SUPPORT_KEYCODE_MAX 4
#define IL_BUTTON_SUPPORT_CALLBACK_MAX 8

typedef void (*il_button_cb)(void);

typedef enum
{
    IL_TEXT_BUTTON,
    IL_IMAGE_BUTTON,

    IL_BUTTON_TYPE_MAX
} il_button_type;

typedef enum
{
    IL_BUTTON_UP,
    IL_BUTTON_DOWN,
    IL_BUTTON_DISABLE,

    IL_BUTTON_STATUS_MAX
} il_button_status;

typedef union
{
    il_label* label;
    il_image* images[IL_BUTTON_STATUS_MAX];
} il_button_element;

typedef struct
{
    /* base */
    il_control base;

    /* attributes */
    il_button_type type;
    il_button_status status;
    il_button_element elem;
    ILINT key_code_list[IL_BUTTON_SUPPORT_KEYCODE_MAX];//internal used : store key codes binding to this button
    ILINT if_selected_by_down_event;//internal used : if this button selected by pen down or key down
    il_button_cb down_cb[IL_BUTTON_SUPPORT_CALLBACK_MAX];//internal used
    il_button_cb up_cb[IL_BUTTON_SUPPORT_CALLBACK_MAX];//internal used

    /* methods */

    /*
     *	[description] change button status
     *  [param] ctrl_p : which one to deal pen
     *  [param] status : enum of il_button_status
     *  [return] il_ret : IL_OK or error code
     */
    il_ret (*change_status)(il_control* ctrl_p, il_button_status status);

    /*
     *	[description] reset button status,reset to up status
     *  [param] ctrl_p : which one to deal pen
     *  [return] il_ret : IL_OK or error code
     */
    il_ret (*reset_status)(il_control* ctrl_p);

    /*
     *	[description] add key to tie on this button
     *  [param] ctrl_p : which one to deal key
     *  [param] key_code : which key
     *  [return] il_ret : IL_OK or error code
     */
    il_ret (*add_keycode)(il_control* ctrl_p, ILINT key_code);

    /*
     *	[description] delete key from key_list tied on this button
     *  [param] ctrl_p : which button to deal key
     *  [param] key_code : which key
     *  [return] il_ret : IL_OK or error code
     */
    il_ret (*delete_keycode)(il_control* ctrl_p, ILINT key_code);

    /*
     *	[description] add callback to button status(il_button_status),it's a list,and when the
     *                 status happens,all callback functions will be called.
     *  [param] ctrl_p : which button to add callback
     *  [param] status : enum of il_button_status
     *  [param] p : callback function
     *  [return] il_ret : IL_OK or error code
     */
    il_ret (*add_cb_by_status)(il_control* ctrl_p, il_button_status status, il_button_cb p);

    /*
     *	[description] delete an existed callback function from the callback list of this button status(il_button_status).
     *  [param] ctrl_p : which button to delete callback function
     *  [param] status : enum of il_button_status
     *  [param] p : callback function
     *  [return] il_ret : IL_OK or error code
     */
    il_ret (*delete_cb_by_status)(il_control* ctrl_p, il_button_status status, il_button_cb p);

    /*
     *	[description] just for image button,you can set offset of images in button area.
     *  [param] ctrl_p : which button
     *  [param] x_off : axis of x, relative to button area
     *  [param] y_off : axis of y, relative to button area
     *  [return] il_ret : IL_OK or error code
     */
    il_ret (*set_show_offset)(il_control* ctrl_p, ILINT x_off, ILINT y_off);
} il_button;

/*
 *	[description] create a button control
 *  [param] area : area of this control
 *  [param] type : il_button_type
 *  [param] param1 : if text button,it is text;if image button,it is up_img path
 *  [param] param2 : if text button,it is NULL;if image button,it is down_img path
 *  [param] param3 : if text button,it is NULL;if image button,it is disable_img path
 *  [param] img_src_type : if text button,it is NULL;if image button,it is image source type
 *  [return] il_button* : if NULL , means create failed.
 *                       else return the pointer of label.
 */
il_button* il_ctrl_button_create(ILUINT8* paint_buf, il_rect area, il_button_type type,
                                 ILWSTR param1, ILWSTR param2, ILWSTR param3, ILUINT img_src_type);
//il_button* il_ctrl_text_button_create(ILUINT8* paint_buf, il_rect area, ILWSTR text);
//il_button* il_ctrl_image_button_create(ILUINT8* paint_buf, il_rect area, ILWSTR up_img,ILWSTR down_img,VMSTR disable_img);
/*
 *	[description] destroy a existed label
 *  [param] ctrl_button_p : pointer of button control
 *  [return] il_ret : IL_OK means destroy successful,else are abnormal.
 */
il_ret il_ctrl_button_destroy(il_button* ctrl_button_p);

#endif//__IL_BUTTON__H__